Code sample Home

Insert new polyline vertex by LC_EVENT_LBDOWN event

When user presses left mouse button on a polyline segment, the new vertex position will be added at this place.

...
lcEventSetProc( LC_EVENT_LBDOWN, EventProc, 0, 0 );
...
  
//-----------------------------------------------
void CALLBACK EventProc (HANDLE hEvent)
{
  int EventType;
  EventType = lcPropGetInt( hEvent, LC_PROP_EVENT_TYPE );
  switch( EventType ){
    ...
    case LC_EVENT_LBDOWN:  
      OnLBDown( hEvent );  
      break;
    ...
  }
}

//-----------------------------------------------
void OnLBDown (HANDLE hEvent)
{
  HANDLE hLcWnd, hEnt, hNewVer;
  int    EntType;
  double Delta, X, Y;

  hLcWnd = lcPropGetHandle( hEvent, LC_PROP_EVENT_WND );
  // get entity by cursor position
  hEnt = lcWndGetEntByPoint( hLcWnd, -1, -1 );
  if (hEnt){
    // check if the entity is a polyline
    EntType = lcPropGetInt( hEnt, LC_PROP_ENT_TYPE );
    if (EntType == LC_ENT_POLYLINE){
      // cursor coordinates (drawing coordinate space)
      X = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT1 );
      Y = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT2 );
      // delta is the current size of cursor selecting square
      Delta = lcPropGetFloat( hLcWnd, LC_PROP_WND_PICKBOXSIZE );
      // insert vertex oa the polyline at cursor position
      hNewVer = lcPlineAddVerPt( hEnt, X, Y, Delta );
      if (hNewVer){
        // undate view
        lcEntUpdate( hEnt );
        lcWndRedraw( hLcWnd );
        // disable default Litecad reaction on the event
        lcEventReturnCode( 1 );
      }
    }
  }
}